#include <iostream>
#include <string>
using namespace std;
int gcd_nonneg(int a,int b)
{
    if (b == 0)
        return a;
    if (a<b)
        return gcd_nonneg(b, a);
    return gcd_nonneg(a % b, b);
}
int main()
{
    int n;
    int lcm, gcd, year;
    int i, c, d, m, lastd, lastm;
    cin>>n;
    for (i = 1; i <=n; i++){
        cin>>gcd>>lcm>>year;
        //cout<<gcd<<" "<<lcm<<" "<<year<<endl;
        int md = lcm * gcd;
        c = 0;
        for (m = gcd; m<=12 && m <= lcm; m+=gcd) {
            if (lcm % m != 0)
                continue;
            d = md / m;
            if (lcm % d != 0 || d % gcd != 0 || d >31)
                continue;
            if (gcd_nonneg(m, d) != gcd)
                continue;
            if (m == 2){
                if (d >29)
                    continue;
                else if(d == 29){
                    if (!(year % 400 == 0 || (year %100 != 0 && year %4 == 0))){
                        continue;
                    }
                }
            } else if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10|| m == 12){

            } else if (d == 31){
                continue;
            }

            c++;
            lastm = m;
            lastd = d;
        }
        switch(c) {
        case 0:
            cout<< "Case #"<<i<<": "<< -1;
            break;
        case 1:
            cout<< "Case #"<<i<<": "<< year<<"/";
            if (lastm<10)
                cout<<"0";
            cout<<lastm<<"/";
            if (lastd<10)
                cout<<"0";
            cout<<lastd;
            break;
        default:
            cout<< "Case #"<<i<<": "<< 1;
            break;
        }
        if (i< n)
            cout<<endl;
    }
}
